package com.usian.wemedia.controller;/*
 *文件名：WmUserController
 *创建者：宋璟
 *创建时间:2023/2/7 20:39
 *描述: TODO
 */

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.admin.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vi/user")
public class WmUserController implements WmUserControllerApi {
    @Autowired
    private WmUserServiceImpl service;

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody WmUser dto){
        if (dto == null)return service.paramError();
        service.save(dto);
        return ResponseResult.okResult(dto);
    }

    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable("name") String name) {
        return service.getOne(Wrappers.<WmUser>lambdaQuery().eq(StringUtils.isNotEmpty(name),WmUser::getName,name));
    }

    @PostMapping("/updateAuthorId")
    //@Override
    public ResponseResult updateAuthorId(@RequestBody WmUser dto){
        if (dto == null)return service.paramError();
        service.updateById(dto);
        return service.success;
    }

}
